package com.bit.controller;

import com.bit.Model.User;
import com.bit.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

//将当前的类存储到Spring当中
@Controller
public class UserController {

    //方法二：Setter注入
    private UserService userService;
    @Autowired
    @Qualifier(value = "u2")
    private User user;

    public User getUser() {
        return user;
    }

    @Resource
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    /*
    //方法一：属性注入
    @Resource
    private UserService userService;
    */

    /*
    //方法3：构造方法注入
    private UserService userService;
    @Autowired
    public UserController(UserService userService){
        this.userService = userService;
    }
    */

    /*
    //方法二：Setter注入
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    */

    /*
    //方法一：属性注入
    @Autowired
    private UserService userService;
    */

    public User findUserById(Integer id){
        if(null==id){
            return new User();
        }
        return userService.findUserById(id);
    }
    public void sayHi(String name){
        System.out.println(name+":hi controller");
    }
}
